package cn.microservices.cloud.common.core.utils;

/**
 * @author yjq
 * @version 1.0
 * @date 2021/10/29 19:07
 */
public class ValidateUtils {
    /**
     * 验证邮箱格式
     * @param email
     * @return
     */
    public static boolean validEmail( String email){
        return email.matches("^[A-Za-z\\d]+([-_.][A-Za-z\\d]+)*@([A-Za-z\\d]+[-.])+[A-Za-z0-9]{2,4}$");
    }

    /**
     * 验证手机号格式
     * @param phone
     * @return
     */
    private static boolean validPhoneFormat(String phone){
        return phone.matches("^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$");
    }
    /**
     * 验证手机号长度
     * @param phone
     * @return
     */
    private static boolean validPhoneLength(String phone){
        return phone.length()==11;
    }

    /**
     * 验证手机号
     * @param phone
     * @return
     */
    public static boolean validPhone(String phone){
        if(validPhoneLength(phone)&&validPhoneFormat(phone)){
            return true;
        }
        return false;
    }


}
